package com.market.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.market.entity.StoreCashFlow;
import com.market.service.StoreCashFlowService;
import com.market.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName StoreCashFlowController
 * @Description 小店资金流水
 * @Author pq
 * @Date 2022/3/30 17:03
 * @Version 1.0
 */
@RestController
@RequestMapping("storeCashFlow")
public class StoreCashFlowController {
    @Autowired
    StoreCashFlowService storeCashFlowService;
    //增加小店流水
    @PostMapping("addStoreCashFlow")
    public R addStoreCashFlow(@RequestBody StoreCashFlow storeCashFlow){
        if(storeCashFlowService.addStoreCashFlow(storeCashFlow)){
            return new R(200,"增加小店流水成功",null);
        }else{
            return new R(200,"增加小店流水失败",null);
        }
    }

    //根据小店id查看所有流水
    @GetMapping("queryAllStoreCashFlow")
    public R queryAllStoreCashFlow(int storeId,int currentPage,int pageSize){
        PageHelper.startPage(currentPage, pageSize);
        List<StoreCashFlow> result = storeCashFlowService.queryAllStoreCashFlowByStoreId(storeId);
        if(result.size()!=0){
            return new R(200,"查看小店所有流水成功",new PageInfo<>(result));
        }else{
            return new R(201,"查看小店所有流水失败",null);
        }
    }
}
